package com.xc.common.object;

import java.util.ArrayList;
import java.util.List;
import org.jooq.Record;
import org.jooq.Result;

public class PageInfo<T> {
	@SuppressWarnings({ "unchecked", "rawtypes" })
	private List<T> list = new ArrayList();
	private Result<Record> result;
	private Long count;
	private Integer limit;
	private Integer pageNo;

	public PageInfo() {
	}

	public PageInfo(Integer limit, Integer pageNo) {
		this.limit = limit;
		this.pageNo = pageNo;
	}

	public List<T> getList() {
		return this.list;
	}

	public void setList(List<T> list) {
		this.list = list;
	}

	public Result<Record> getResult() {
		return this.result;
	}

	public void setResult(Result<Record> result) {
		this.result = result;
	}

	public Long getCount() {
		return this.count;
	}

	public void setCount(Long count) {
		this.count = count;
	}

	public Integer getLimit() {
		return this.limit;
	}

	public void setLimit(Integer limit) {
		this.limit = limit;
	}

	public Integer getPageNo() {
		return this.pageNo;
	}

	public void setPageNo(Integer pageNo) {
		this.pageNo = pageNo;
	}

	public int getBeginNum() {
		int beginNum = this.limit.intValue() * (this.pageNo.intValue() - 1);
		return beginNum;
	}

	public long getLastNum() {
		return getBeginNum() + this.limit.intValue() - 1;
	}

	public Long getTotalPageNo() {
		long totalPageNo = this.count.longValue() / this.limit.intValue();
		long rest = this.count.longValue() % this.limit.intValue();
		if (rest > 0L) {
			totalPageNo += 1L;
		}
		return totalPageNo;
	}
}
